package system

import (
	"context"
	"fmt"
	"private-domain-overseas-service/admin/business/api/internal/repository/system"
	"private-domain-overseas-service/admin/business/api/internal/svc"
	"private-domain-overseas-service/admin/business/api/internal/types"
	"private-domain-overseas-service/pkg/xerr"
	"private-domain-overseas-service/tools/ent"
	"time"

	"github.com/zeromicro/go-zero/core/logx"
)

type SystemVersionDeleteLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

// NewSystemVersionDeleteLogic - 删除版本信息
func NewSystemVersionDeleteLogic(ctx context.Context, svcCtx *svc.ServiceContext) *SystemVersionDeleteLogic {
	return &SystemVersionDeleteLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *SystemVersionDeleteLogic) SystemVersionDelete(req *types.SystemVersionDeleteRequest) error {
	// 创建实例
	versionDao := system.NewSystemVersionDao(l.ctx, l.svcCtx)

	// 组装参数
	versionInfo := &ent.HzSystemAppVersion{
		ID:       int(req.Id),
		DeleteAt: time.Now().Unix(),
	}

	// 删除版本信息
	err := versionDao.SystemVersionDelete(versionInfo, nil)
	if err != nil {
		return xerr.ErrCodeMsg(xerr.ServerOperationExceptionError, fmt.Sprintf("删除版本信息失败：%s", err.Error()))
	}

	return nil
}
